package com.climber.android.lib_share.sensor

import java.util.HashMap

/**
 * Created by Mikes at 2020-03-19 23:43
 */
interface ShareAction{
    fun shareText()
    fun shareImage()
    fun shareMusic()
    fun shareVideo()
    fun shareWebPage()
    fun shareFile()
    fun shareMiniProgram()
}

/**
 * 内部封装第三方登录结果
 */
interface AuthorizeAction{
    /**
     * 要功能，不要数据
     *
     * 没有自己的独立账户系统，需要第三方平台校验授权用户。
     *
     * 入口方法是authorize()；
     */
    fun doAuthorize(builder: AuthorizeResultCallBack.Builder.() -> Unit)

    /**
     * 要数据，不要功能
     *
     * 有自己独立的用户系统，只需要第三方平台的用户，不要他们的验证功能
     *
     * 入口方法是showUser(null)；
     */
    fun doUserInfo(builder: AuthorizeResultCallBack.Builder.() -> Unit)
}

class EmptyAuthorizeAction : AuthorizeAction{
    override fun doAuthorize(builder: AuthorizeResultCallBack.Builder.() -> Unit) {
    }

    override fun doUserInfo(builder: AuthorizeResultCallBack.Builder.() -> Unit) {
    }
}

class ShareResultCallBack{
    lateinit var builder: Builder

    // 带Builder返回值的lambda
    fun registerListener(builder: Builder.() -> Unit) {
        this.builder = Builder().also(builder)
    }

    inner class Builder{
        internal var error: (() -> Unit)? = null
        internal var success: (() -> Unit)? = null
        internal var cancel: (() -> Unit)? = null

        fun onError(action: () -> Unit) {
            error = action
        }

        fun onSuccess(action: () -> Unit) {
            success = action
        }

        fun onCancel(action: () -> Unit) {
            cancel = action
        }
    }
}

class AuthorizeResultCallBack{
    lateinit var builder: Builder

    // 带Builder返回值的lambda
    fun registerListener(builder: Builder.() -> Unit) {
        this.builder = Builder().also(builder)
    }

    inner class Builder{
        internal var error: (() -> Unit)? = null
        internal var success: ((value: Map<String, Any>) -> Unit)? = null
        internal var cancel: (() -> Unit)? = null

        fun onError(action: () -> Unit) {
            error = action
        }

        fun onSuccess(action: (value: Map<String, Any>) -> Unit) {
            success = action
        }

        fun onCancel(action: () -> Unit) {
            cancel = action
        }
    }
}